/*
 * consola_disco_main.c
 *
 *  Created on: 19/10/2011
 *      Author: utn_so
 */
#define SOCK_PATH "echo_socket"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>


int main() {
	int descriptorSocket, t, len;
	struct sockaddr_un dirRemota;
	char str[100];
	printf("CONSOLA INICIADA. \n");

	if ((descriptorSocket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
		perror("socket");
		exit(1);
	}

	printf("INTENTANDO CONECTARSE AL PLANIFICADOR...\n");

	dirRemota.sun_family = AF_UNIX;
	strcpy(dirRemota.sun_path, SOCK_PATH);
	len = strlen(dirRemota.sun_path) + sizeof(dirRemota.sun_family);
	if (connect(descriptorSocket, (struct sockaddr *) &dirRemota, len) == -1) {
		perror("connect");
		exit(1);
	}

	printf("CONECTADA!\n");
/*
	while (printf("> "), fgets(str, 100, stdin), !feof(stdin)) {
		if (send(descriptorSocket, str, strlen(str), 0) == -1) {
			perror("send");
			exit(1);
		}

		if ((t = recv(descriptorSocket, str, 100, 0)) > 0) {
			str[t] = '\0';
			printf("echo> %s", str);
		} else {
			if (t < 0)
				perror("recv");
			else
				printf("Server closed connection\n");
			exit(1);
		}
	}
*/
	close(descriptorSocket);

	return 2;
}
